# !/usr/bin/env python
# -*-coding:utf-8 -*-

"""
# File       : 将API调用封装为函数.py
# Time       ：2025-04-14 21:43
# Author     ：ybli
# Description：
"""
import requests

def deepseek(question):
    url = "https://api.siliconflow.cn/v1/chat/completions"

    payload = {
        "model": "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B",
        "stream": False,
        "max_tokens": 512,
        "temperature": 0.7,
        "top_p": 0.7,
        "top_k": 50,
        "frequency_penalty": 0.5,
        "n": 1,
        "messages": [
            {
                "content": question,
                "role": "user"
            }
        ]
    }
    headers = {
        "Authorization": "Bearer sk-ggsvpwiznzulbcybuabfievxfgqgyouyxeqnnhbifpudcikx",
        "Content-Type": "application/json"
    }

    response = requests.request("POST", url, json=payload, headers=headers)

    return response.json().get("choices")[0]\
        .get("message").get("content")


# 调用deepseek
if __name__ == "__main__":
    question = "你是谁？"
    answer = deepseek(question)
    print(answer)

